﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace QuanLyDoiXe.Lop_du_lieu
{
    public class Lop_lay_du_lieu
    {
        public Lop_lay_du_lieu()
	{
        lop_ket_noi.thietlapketnoi();
	}
    public DataSet getdata(string truyvan)
    {
        try
        {
            DataSet ds = new DataSet(); ;
            SqlCommand cmd = new SqlCommand(truyvan, lop_ket_noi.conn);
            SqlDataAdapter sqlDA = new SqlDataAdapter(cmd);
            sqlDA.Fill(ds, "bang");
            lop_ket_noi.huyketnoi();
            return ds;

        }
        catch { return null; }
    }
    public SqlDataReader lay_reader(string truyvan)
    {
        try
        {
            DataSet ds = new DataSet(); ;
            SqlCommand cmd = new SqlCommand(truyvan, lop_ket_noi.conn);
            SqlDataReader dr = cmd.ExecuteReader();

            return dr;

        }
        catch { return null; }
    }
    public int thucthitruyvan(string truyvan)
    {
        try 
        {
            SqlCommand cmd = new SqlCommand(truyvan, lop_ket_noi.conn);
            cmd.ExecuteNonQuery();
            return 1;
        }
        catch
        {
            return 0;
        }
        
    }
    }
}
